﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Noebe.Orm.Core;
using System.Data;
using Pixysoft.Framework.Noebe.Orm.Controller;
using Pixysoft.TestDrivens;
using Pixysoft.Framework.XSchEmA;

namespace Pixysoft.Framework.Noebe.Orm.testdriven
{
    class tc_005
    {
        public void test001()
        {
            string path = StringFilter.RegularPath(AppDomain.CurrentDomain.BaseDirectory) + "helloworld.mdb";

            NoebeConfiguration config = new NoebeConfiguration();
            config.DatabaseType = DatabaseType.Access;
            config.Filename = path;

            NoebeManager.Reload(config);

            string objectname = ReflectHelper.GetInterfaceTypeName(typeof(Person));
            string tbname = MappingHelper.GetTableName(objectname);
            string sidname = MappingHelper.GetSysIDName();
            string tobjectname = ReflectHelper.GetInterfaceTypeName(typeof(Car));


            DataTable table = OrmCommandController.GetSchema(tbname);
            DataRow row = table.NewRow();
            row[sidname] = StringHelper.CreatePrimaryKey();

            ObjectProxy proxy = new ObjectProxy(StructStatus.Select, row);

            proxy.SetValue("StringValue", "13");
            Assert.Write(proxy.GetValue("StringValue"));
            proxy.DeleteValue("StringValue");



            DataTable table2 = OrmCommandController.GetSchema(MappingHelper.GetTableName(tobjectname));
            DataRow row2 = table2.NewRow();
            row2[sidname] = StringHelper.CreatePrimaryKey();
            ObjectProxy proxy2 = new ObjectProxy(StructStatus.Select, row2);

            proxy.GetObject("OrmObject", tobjectname);
            proxy.SetObject("OrmObject", proxy2);
            proxy.DeleteObject("ormObject");


            List<string> vlist = new List<string>();
            vlist.Add("helloworld");
            proxy.GetValueList("StringList");
            proxy.SetValueList("StringList", vlist);
            proxy.DeleteValueList("StringList");
            proxy.AddToValueList("StringLIst", vlist);
            proxy.RemoveFromValueList("StringLIst", vlist);


            string upkname = "stringvalue";
            object upk = "123";
            Assert.Write(proxy.Contains("OrmList", tobjectname, upkname, upk));


            List<ObjectProxy> proxylist = new List<ObjectProxy>();
            proxylist.Add(proxy2);
            proxy.SetList("OrmList", proxylist);
            Assert.Write(proxy.GetList("Ormlist", tobjectname).Count);
            proxy.DeleteList("OrmList");
            proxy.AddToList("OrmList", proxylist.ToArray());
            proxy.RemoveFromList("OrmList", proxylist.ToArray());

        }
    }
}
